package com.example.demo.web;

import com.example.demo.domain.User;
import com.example.demo.services.UserServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import java.util.List;
@Controller
public class UserController {
    @Autowired
    UserServer userServer;
    @RequestMapping("/ListUser")
    @ResponseBody
    public List<User> returnList(){
        return userServer.retrunList();
    }
    @RequestMapping("/reqIndex")
    public String reqIndex(){
        return "index";
    }
//    @ModelAttribute("finsUser")
    @GetMapping("/findsUser")
    @ResponseBody
    public String findsUser(Model model){
        model.addAttribute("finsUser",userServer.retrunList());
        return "index";
    }
    @GetMapping("/RedirectInfo")
    public ModelAndView RedirectInfo(){
        ModelAndView modelAndView=new ModelAndView("info");
        return modelAndView;
    }
    @GetMapping("/redirect")
    public String redirect(){
        return "redirect:/info";
    }
//    @GetMapping("/data")
//    public String getDataParam(@RequestParam String type) {
//        System.out.println(type);
//         return "index";
//    }

}
